package ws.cmpe451.group7.ourcity.webservice.comment;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import cmpe451.group7.ourcity.dao.CommentDAO;
import cmpe451.group7.ourcity.entity.Comment;

/**
 * Controller for handling comments
 */
@Controller
public class CommentController {

	@Autowired
	private CommentDAO commentDAO;

	
	/**
	 * Delete the comment with the given id (DEBUGGING PURPOSES ONLY)
	 * 
	 * @param request
	 * @param response
	 * @throws IOException
	 */
	@RequestMapping("/webservice/comment/delete")
	public void delete(HttpServletRequest request, HttpServletResponse response)
			throws IOException {
		String id_string = request.getParameter("commentID");
		long id = Long.parseLong(id_string);
		Comment comment = commentDAO.findByID(id);
		commentDAO.delete(comment);

		ServletOutputStream outputStream = response.getOutputStream();
		PrintWriter out = new PrintWriter(outputStream);

		out.printf("Comment %d is deleted !\n", id);
		out.flush();
	}

}
